package com.lw.leetcode.node;

/**
 * 面试题 04.06. 后继者
 *
 * @Author liw
 * @Date 2021/5/20 16:17
 * @Version 1.0
 */
public class InorderSuccessor {

    boolean flag = false;
    TreeNode node = null;
    public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
        find(root, p);
        return node;
    }
    public boolean find(TreeNode root, TreeNode p) {
        if (root == null) {
            return false;
        }
        boolean f = find(root.left, p);
        if (f) {
            return f;
        }
        System.out.println(root.val);
        if (flag) {
            node = root;
            return true;
        }
        if (root.val == p.val) {
            flag = true;
        }
        return find(root.right, p);
    }

}
